package com.hotel.controllers;

import com.github.pagehelper.PageInfo;
import com.hotel.entitys.RestPOJO;
import com.hotel.entitys.Revenue;
import com.hotel.services.RevenueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@Api(tags="营收汇总接口")//tags:说明信息
public class RevenueController {
    @Autowired
    private RevenueService revenueService;
    @ApiOperation(
            value = "查询所有营收信息",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )

    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="currentPage",value="当前页",required=true),
            @ApiImplicitParam(paramType="query",name="pageSize",value="每页显示的条目数",required=true)

    })

    @GetMapping("/revenue")
    public RestPOJO getAllRevenue(Integer currentPage, Integer pageSize){
        RestPOJO restPOJO = new RestPOJO();
        PageInfo<Revenue> pageInfo = revenueService.selectAllRevenue(currentPage,pageSize);
        if (pageInfo!=null && pageInfo.getList().size()>0){
            restPOJO.setMessage("查询所有营收数据成功");
            restPOJO.setStatus(1000);
            restPOJO.setData(pageInfo);
        }else {
            restPOJO.setMessage("查询所有营收数据失败");
            restPOJO.setStatus(1001);
        }
        return restPOJO;
    }

    @ApiOperation(
            value = "按截止时间查询营收记录",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @GetMapping("/revenue/date")
    public RestPOJO getAllRevenueByDate(String revenue_date) {
        System.out.println(revenue_date);
        RestPOJO restPOJO = new RestPOJO();
        PageInfo<Revenue> pageInfo = revenueService.selectRevenueByDate(revenue_date);
        if (pageInfo!=null && pageInfo.getList().size()>0){
            restPOJO.setMessage("查询营收数据成功");
            restPOJO.setStatus(1000);
            restPOJO.setData(pageInfo);
        }else {
            restPOJO.setMessage("查询营收数据失败");
            restPOJO.setStatus(1001);
            restPOJO.setData(pageInfo);
        }
        return restPOJO;
    }
}
